<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/fns.tld" prefix="fns" %>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <jsp:include page="/resources/inc/head.jsp" />
</head>
<body>
<div style="margin-top: 10px;">
    <div class="layui-form-item" style="margin-left: 20px;margin-top: 30px;">
        <button class="layui-btn test" lay-data="{accept: 'file'}" id="uploadPlan">请选择文件</button>
        <div style="display: inline-block">
            <span id="filename"></span>
        </div>
    </div>
    <div class="layui-form-item" style="margin-left: 20px;">
        <button class="layui-btn" id="doUoload">上传年计划</button>
    </div>
</div>
</div>
<jsp:include page="/resources/inc/footer.jsp" />
<script>
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

    $(function () {
        layui.use('upload', function () {
            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#uploadPlan' //绑定元素
                ,
                url: '${basePath}/oa/wc/deptYearPlan/import' //上传接口
                ,
                auto: false
                ,
                bindAction: '#doUoload'
                ,
                exts: "xls|xlsx"
                ,
                acceptMime: "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                ,
                choose: function (obj) {
                    obj.preview(function (index, file, result) {
                        var name = file.name;
                        $("#filename").text(name);
                    });
                }
                ,
                done: function (res) {
                    //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                    if (res.code == 1) {
                        layer.msg("导入成功", {icon: 1, time: 1000}, function () {
                            parent.layer.close(index);
                            parent.$table.bootstrapTable('refresh');
                        });
                    } else {
                        layer.msg("导入失败", {icon: 5});
                    }
                }
                ,
                error: function () {
                    //请求异常回调
                }
            });
        });
    });
</script>
</body>
</html>
